// map就是遍历数组把所有的val执行放进数组就可以了
const map = (arr, fn) => {
  let results = []
  for (let val of arr) {
    results.push(fn(val))
  }
  return results
}
arr = [1, 2, 3, 4, 5]
console.log(map(arr, (arr) => arr * 2)) //[ 2, 4, 6, 8, 10 ]

// every用来判断数组的每个元素是否都匹配条件
const every = (arr, fn) => {
  let result = true
  for (let val of arr) {
    result = fn(val)
    if (!result) {
      break
    }
  }
  return result
}
console.log(every(arr, (arr) => arr < 6)) // true

// some用来判断数组中是否有一个元素满足条件
const some = (arr, fn) => {
  result = false
  for (let val of arr) {
    result = fn(val)
    if (result) {
      break
    }
  }
  return result
}
console.log(some(arr, (arr) => arr > 6))
